package com.itheima.info.manager.system.service;

import com.itheima.info.manager.system.dao.StudentDao;
import com.itheima.info.manager.system.domain.Student;

public class StudentService {
    private static StudentDao studentDao = new StudentDao();

    //添加学生
    public boolean addStudent(Student student) {
      return studentDao.addStudent(student);
    }
//判断学生是否存在
    public boolean isExists(String sid) {
        Student[] stus = studentDao.findAllStudent();
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null && stu.getSid().equals(sid)) {
                return true;
            }
        }
        return false;
    }
//查看学生
    public Student[] findAllStudent() {
        // 1. 调用库管对象的findAllStudent获取学生对象数组
        Student[] stus = studentDao.findAllStudent();
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null) {
                return stus;
            }
        }
        return null;
    }
    //删除学生
    public void deleteStudent(String sid){
        studentDao.deleteStudent(sid);
    }
    //修改学生
    public void updateStudent(String sid,Student student){
        studentDao.updateStudent(sid,student);
    }
}

